home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1997 / HAM Radio 1997.iso / vcls / sprites / untdmsb2.pas < prev   
Pascal/Delphi Source File  |  1996-04-08  |  4KB  |  134 lines

  1. unit Untdmsb2;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, Mchsprt, ExtCtrls, MChSpBg, MPlayer;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     MChSpriteBgr1: TMChSpriteBgr;
  12.     MChSprite1: TMChSprite;
  13.     MChSprite2: TMChSprite;
  14.     MChSprite3: TMChSprite;
  15.     MediaPlayer1: TMediaPlayer;
  16.     MediaPlayer2: TMediaPlayer;
  17.     procedure FormCreate(Sender: TObject);
  18.     procedure MediaPlayer2Notify(Sender: TObject);
  19.   private
  20.     { Private declarations }
  21.   public
  22.     { Public declarations }
  23.   end;
  24.  
  25. function Sprite2PosFunc(AtTime: TDateTime):TPoint;
  26. function Sprite3PosFunc(AtTime: TDateTime):TPoint;
  27. procedure OnCollide(SprCollided: TMChSprite; AtTime: TDateTime);
  28. procedure NoCollide(AtTime: TDateTime);
  29.  
  30. var
  31.   Form1: TForm1;
  32.  
  33. implementation
  34.  
  35. {$R *.DFM}
  36.  
  37. var
  38.   CollideFlip: Boolean;
  39.  
  40. function Sprite3PosFunc(AtTime: TDateTime):TPoint;
  41.   var
  42.     x,y,alpha: double;
  43.   begin
  44.   alpha:= 2*Pi*(AtTime-Form1.MChSprite3.SprTimeStarted)*24.0*60.0+(90.0+0.0)/180.0*Pi;
  45.   x := Form1.MChSpriteBgr1.ClientWidth /2.0 +
  46.       (Form1.MChSpriteBgr1.ClientWidth /3.0)*cos(alpha);
  47.   y := Form1.MChSpriteBgr1.ClientHeight /2.0 +
  48.     - (Form1.MChSpriteBgr1.ClientWidth /3.0)*sin(alpha);
  49.   Sprite3PosFunc:=Point(round(x),round(y));
  50.   Form1.MChSprite3.SprSetScale(1-1.0*sin(alpha));
  51.   end;
  52.  
  53. function Sprite2PosFunc(AtTime: TDateTime):TPoint;
  54.   var
  55.     x,y,alpha: double;
  56.   begin
  57.   alpha:=-2*Pi*(AtTime-Form1.MChSprite2.SprTimeStarted)*24.0*60.0+(90.0-180.0)/180.0*Pi;
  58.   x := Form1.MChSpriteBgr1.ClientWidth /2.0 +
  59.       (Form1.MChSpriteBgr1.ClientWidth /3.0)*cos(alpha);
  60.   y := Form1.MChSpriteBgr1.ClientHeight*0.5 +
  61.     - (Form1.MChSpriteBgr1.ClientWidth *0.55)*sin(alpha);
  62.   Sprite2PosFunc:=Point(round(x),round(y));
  63.   if x>Form1.MChSpriteBgr1.ClientWidth div 2
  64.     then Form1.MChSprite2.SprSetScaleX( (1-1.0*sin(alpha)))
  65.     else Form1.MChSprite2.SprSetScaleX(-(1-1.0*sin(alpha)));
  66.   if y<Form1.MChSpriteBgr1.ClientHeight div 2
  67.     then Form1.MChSprite2.SprSetScaleY( (1-1.0*sin(alpha)))
  68.     else Form1.MChSprite2.SprSetScaleY(-(1-1.0*sin(alpha)));
  69.   end;
  70.  
  71. procedure TForm1.FormCreate(Sender: TObject);
  72.   begin
  73.    with MediaPlayer1 do
  74.     begin
  75.     Open;
  76.     end;
  77.   with MediaPlayer2 do
  78.     begin
  79.     Open;
  80.     Notify:=True;
  81.     Play;
  82.     end;
  83.   MChSprite3.SprPosFunc:=Sprite3PosFunc;
  84.   MChSprite2.SprPosFunc:=Sprite2PosFunc;
  85.   MChSprite3.SprOnCollide:=OnCollide;
  86.   MChSprite3.SprNoCollide:=NoCollide;
  87.   MChSprite3.SprCruise(-1);
  88.   MChSprite2.SprCruise(-1);
  89.   MChSprite1.SprShowAt(Point(Form1.MChSpriteBgr1.ClientWidth  div 2,
  90.                              Form1.MChSpriteBgr1.ClientHeight div 2));
  91.   end;
  92.  
  93. procedure OnCollide(SprCollided: TMChSprite; AtTime: TDateTime);
  94.   begin
  95.   if SprCollided=Form1.MChSprite2 then
  96.     begin
  97.     if not CollideFlip then
  98.       begin
  99.       {MessageBeep(MB_ICONASTERISK);}
  100.       Form1.MediaPlayer1.Play;
  101.       CollideFlip:=True;
  102.       end;
  103.     if Form1.MChSprite3.SprNextPos.x<Form1.MChSpriteBgr1.ClientWidth div 2 then
  104.       begin
  105.       if Form1.MChSprite3.SprIndex<Form1.MChSprite2.SprIndex then
  106.         Form1.MChSpriteBgr1.BgrSprIndexExchangeZ(Form1.MChSprite3.SprIndex,
  107.           Form1.MChSprite2.SprIndex);
  108.       end
  109.     else
  110.       begin
  111.       if Form1.MChSprite3.SprIndex>Form1.MChSprite2.SprIndex then
  112.         Form1.MChSpriteBgr1.BgrSprIndexExchangeZ(Form1.MChSprite3.SprIndex,
  113.           Form1.MChSprite2.SprIndex);
  114.       end;
  115.     end;
  116.   end;
  117.  
  118. procedure NoCollide(AtTime: TDateTime);
  119.   begin
  120.   if CollideFlip then
  121.     begin
  122.     {MessageBeep(MB_OK);}
  123.     Form1.MediaPlayer1.Stop;
  124.     end;
  125.   CollideFlip:=False;
  126.   end;
  127.  
  128. procedure TForm1.MediaPlayer2Notify(Sender: TObject);
  129.   begin
  130.   if MediaPlayer2.Notifyvalue=nvSuccessful then mediaPlayer2.Play;
  131.   end;
  132.  
  133. end.
  134.